﻿using System;
using System.Windows;
using System.Windows.Input;

namespace FuzzyTaskList
{
    public partial class MainWindow : Window
    {
        TaskSet _tasks;

        public static readonly RoutedCommand AddTaskCommand = new RoutedCommand("AddTask", typeof(MainWindow));



        TaskDataProviderBase<TaskSet> _dataProvider;

        public MainWindow()
        {
            InitializeComponent();
            _dataProvider = DataProviderFactory<TaskSet>.GetDataProvider(Properties.Settings.Default.DataProvider);
            _tasks = _dataProvider.Load();
            this.DataContext = _tasks;      

        }

        

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SaveTasksHandler(sender,null);
        }


        private void SaveTasksHandler(object sender, RoutedEventArgs e)
        {
            _dataProvider.Save(_tasks);
        }
        private void AddTaskHandler(object sender, RoutedEventArgs e)
        {
            FuzzyTaskItem newTaskItem = new FuzzyTaskItem("new task", 1, 5);
            _tasks.TaskCollection.Add(newTaskItem);
            lbTasks.SelectedItem = newTaskItem;

        }
    }
}
